<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>    
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 
 
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
<!--area_lista_serv_cliente.jsp-->
<script type="text/javascript">
var listaAutisti =<c:out value="${listaAutisti}" escapeXml="false" 	/>;

    $(document).ready(function () {
        $('#listServizi').jtable({
        	defaultDateFormat: 'dd/mm/yy',
        	paging: true,
        	pagesize: 10,
        	pageList: 'minimal',
        	sorting: 'true',
            title: 'Lista di tutti i servizi del cliente <c:out value="${cliente.descNome}" />',
            toolbar: {
            	 hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
            	 hoverAnimationDuration: 60, //Duration of the hover animation.
           	     hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
            	    
                items: [{
                    icon: '/images/excel.png',
                    text: 'Export to Excel',
                    click: function () {
                        //perform your custom job...
                    }
                },{
                    icon: '/images/pdf.png',
                    text: 'Export to Pdf',
                    click: function () {
                        //perform your custom job...
                    }
                }]
            },
            actions: {
                listAction: '<%=request.getContextPath()%>/areaPrivata/ajax/dettaglioCliente.html?id=<c:out value="${cliente.idCliente}" />',
            },
            fields: {
                idServ: {
                    key: true,
                    list: false,
                    create: false,
                    edit: false
                },
                idServUserJson: {
                    title: 'Id',
                    width: '4%',
                    create: false,
                    edit: false,
                    display: function (data) {
                    	if (data.record) {
                    		return data.record.idServUser;
                    	}
                    }
                },
                idServUser: {
                    create: false,
                    type: 'hidden',
                    defaultValue: function (data) {return data.record.idServUser; }
                },
//                 idUserInse: {
//                     type: 'hidden'
//                 },
                tipoServizio: {
                	list: false,
                    title: 'Tipo Corsa',
                    width: '8%',
                    options: { '1': 'Transfer', '2': 'Disposizione' }
                },   
                dataInseJson: {
                    create: false,
                    edit: false,
                    type: 'hidden'
                    
                },
             
                oraJson: {
                    title: 'Ora',
                    width: '3%',
                    sorting: false,
                	inputClass: 'validate[required,custom[orario]]'
                },
                dataJson: {
                    title: 'Data',
                    width: '7%',
                    type: 'date',
                    inputClass: 'validate[required]',
                    listClass: 'grassetto'
                 //   inputClass: 'validate[funcCall[checkData],required]'
                },
                'idCliente': {
                    type: 'hidden',
                 	defaultValue: function (data) {return data.record.cliente.idCliente; },
                	create: false
                },
                'cliente.descNome': {
                	title: 'Cliente',
                    width: '10%',
                    sorting: true,
	                 display: function (data) {
	                	 var str = data.record.cliente.descNome +'<br/>'+ data.record.cliente.telefono  +'<br/>'+ data.record.cliente.email;
	                     return str;
	                 },
	                input: function (data) {
	                    if (data.record) {
	                        return '<input type="text" name="cliente.descNome" style="width:200px" value="' + data.record.cliente.descNome + '" />';
	                    } else {
	                        return '<input type="text" name="cliente.descNome" style="width:200px" />';
	                    }
	                }
             	},
                'cliente.telefono': {
                	title: 'Tel.',
		            list: false,
		             
	                 display: function (data) {
	                     return data.record.cliente.telefono;
	                 },
	                input: function (data) {
	                		if (data.record) {
	                        	return '<input type="text" name="cliente.telefono" style="width:200px" value="' + data.record.cliente.telefono + '" />';
	                        } else {
	                        	return '<input type="text" name="cliente.telefono" style="width:200px" value="" />';
	                        }
	                }
             	},  
                'cliente.email': {
                	title: 'Email Cliente',
                    list: false,
	                 display: function (data) {
	                     return data.record.cliente.email;
	                 },
	                input: function (data) {
	                    if (data.record) {
	                        return '<input type="text" name="cliente.email" style="width:200px" value="' + data.record.cliente.email + '" />';
	                    } else {
	                        return '<input type="text" name="cliente.email" style="width:200px" />';
	                    }
	                }
             	},               	
                pax : {
                    title: 'Pax',
                    width: '3%',
                    options: ['1','2','3','5','6','7','8','9','10','15','25'],
                    sorting: false
                    
                },
                volo: {
                    title: 'Volo / Nave',
                    width: '5%'
                },
                
                pickUp: {
                    title: 'Pick up',
                    width: '17%'
                },
                dropOff: {
                    title: 'Drop off',
                    width: '17%'
                },
                
                prezzo: {
                    title: '&euro;',
                    width: '4%',
                    listClass: 'grassetto',
                    defaultValue: '0',
                    display:	function (data) {
	                    if (data.record) {
	                        return '&euro; ' + data.record.prezzo;
	                    } 
                    }
                	
                },
                dare: {
                    title: 'Dare',
                    width: '3%',
                    defaultValue: '0'
                },
                avere: {
                    title: 'Avere',
                    width: '3%',
                    defaultValue: '0'
                },    
                idSorgente : {
                    title: 'Proveniente da collaboratore:',
                    options: listaAutisti,
                    list: false
                },
                idAutista : {
                    title: 'Eseguito da',
                    list: false,
                    options: function (data) { return listaAutisti; }
                },
                nomeAutista : {
                    title: 'Eseguito da',
                    create: false,
                    edit: false,
                    display: function (data) { return data.record.nomeAutista; }
                },
                descTipoServizio: {
                    title: 'Tipo Corsa',
                    width: '8%',
                    edit: false,
                    create: false,
				    sorting: false
                },
                       
//                  TestColumn: {
//                      title: 'Test',
//                      display: function (data) {
//                          return data.record.cliente.descNome;
//                      }
//                  }
                    
            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                data.form.validationEngine();
            },
            //Validate form when it is being submitted
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            //Dispose validation logic when form is closed
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                //data.form.validationEngine('detach');
            }
        });
        
        $('#listServizi').jtable('load');

    });
    
    
    function checkData(field, rules, i, options){
    		    var pattern = /^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.]([0-9]{4})$/; 
    		    var str = field.val();
    		    if (!str.match(pattern)) {
    	    	     return options.allrules.validate2fields.alertText;

    		    }
    		    
    	     // this allows the use of i18 for the error msgs
   }

    
    
    

    
</script>
			
			
	<!-- INIZIO CONTENUTO -->
				
<div id="listServizi" class="listaJtable"></div>
	<!-- FINE CONTENUTO -->












</div>
		</div>			